import { $get, $post, $put, $delete } from '@js/request'

export async function getInfoListByName (name: string, type: string) {
  const res = await $get('/api/commission/agent/getByName', {
    name,
    subject_type: type
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}

// 添加当事人
export async function addAgentRequest (data: { [k: string]: any }) {
  const res = await $post('/api/commission/agent', data)
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return {
    ...data,
    id: res.data
  }
}

// 更新当事人
export async function updateAgentRequest (data: { [k: string]: any }) {
  const res = await $put(`/api/commission/agent/${data.id}`, data)
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return data
}

// 删除当事人
export async function deleteAgentRequest (id: string) {
  const res = await $delete(`/api/commission/agent/${id}`)
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return id
}
